using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class TankBase : MonoBehaviour
{
    public float atk;
    public float def;
    public float originalmaxHp;
    public float hp;
    public float moveSpeed = 8;
    public float roundSpeed = 100;
    public float headRoundSpeed = 100;
    public GameObject deadEffect;
    //坦克头部
    public GameObject head;

    public WeaponObject nowWeapon;
    /// <summary>
    /// 开火
    /// </summary>
    public virtual void Fire()
    {
        if (nowWeapon != null)
        {
            nowWeapon.Fire();
        }
    }
    /// <summary>
    /// 被攻击，受到伤害
    /// </summary>
    /// <param name="other"></param>
    public virtual void Wound(TankBase other)
    {
        float damage = other.atk - def;
        if (damage <= 0)
            return;
        if (damage > 0)
        {
            hp -= damage;
        }
        if (hp <= 0)
        {
            hp = 0;
            if (deadEffect != null)
            {
                DeadEffect();

            }
            else
                Debug.Log(gameObject.name + "无死亡特效");
        }
    }
    /// <summary>
    /// 死亡
    /// </summary>
    public virtual void DeadEffect()
    {


        //死亡特效
        GameObject effobj = Instantiate(deadEffect, transform.position, transform.rotation);
        //获取音效组件
        AudioSource effct = effobj.GetComponent<AudioSource>();
        //设置音效音量
        effct.volume = GameDataMgr.Instance.soundData.soundEffectValue;
        //设置是否静音
        effct.mute = GameDataMgr.Instance.soundData.isOnSoundEffect;
        //播放，防止未勾选play on awake
        effct.Play();
        Destroy(gameObject);

    }

}
